<!-- 活动类型管理 -->
<template>
  <page-header-wrapper>
    <a-card class="table-card">
      <GzSearchForm :searchFunc="searchFunc" :resetFunc="()=>{ searchData = {} }">
        <!-- <GzTextUp placeholder="活动类型ID" v-model:value="searchData['activityTypeNo']"/> -->
        <GzTextUp v-model:value="searchData['activityTypeName']" placeholder="活动类型名称" />
      </GzSearchForm>

      <!-- 列表渲染 -->
      <GzTable
        ref="infoTableRef"
        :init-data="true"
        :req-table-data-func="reqTableDataFunc"
        :table-columns="tableColumns"
        :search-data="searchData"
        row-key="activityTypeNo"
        :scrollX="0"
      >
        <template #topBtnSlot>
          <a-button v-if="$access('ENT_ACTIVITY_TYPE_INFO_ADD')" type="primary" @click="addOrEditFunc(false)">
            <plus-outlined />新建
          </a-button>
        </template>

        <template #bodyCell="{ column, record }">
          <template v-if="column.key == 'operation'">
            <a-button v-if="$access('ENT_ACTIVITY_TYPE_INFO_EDIT')" type="link" @click="addOrEditFunc(record)">修改</a-button>
            <a-button v-if="$access('ENT_ACTIVITY_TYPE_INFO_DEL')" type="link" danger @click="activityTypeDelete(record.activityTypeNo)">删除</a-button>
          </template>
        </template>
      </GzTable>
    </a-card>
    <!-- 新增OR修改 -->
    <AddOrEdit ref="addOrEditRef" :callBackFunc="searchFunc" />
  </page-header-wrapper>
</template>

<script lang="ts" setup>
import AddOrEdit from './AddOrEdit.vue'
import { ref, reactive, getCurrentInstance } from 'vue'
import{$getActiveList,$activityTypeDelete} from '@/api/activityManage/activityType/index'
const { $infoBox, $access } = getCurrentInstance()!.appContext.config.globalProperties


const infoTableRef = ref()
const addOrEditRef = ref()

const tableColumns = reactive([
  { key: 'activityTypeNo', title: '活动类型编号',dataIndex: 'activityTypeNo' },
  { key: 'activityTypeName', title: '活动类型名称',dataIndex: 'activityTypeName' },
  { key: 'remark', title: '活动类型描述', dataIndex:'remark' },
  { key: 'operation', title: '操作', dataIndex: 'operation', align: 'center' }
])
const searchData:any = ref({
  
})

// 请求table接口数据
function reqTableDataFunc(params: any) {
  return $getActiveList(params)
}

function searchFunc() {
  infoTableRef.value.refTable(true)
}
// 新增OR修改
function addOrEditFunc(record){
  addOrEditRef.value.show(record)
}
// 删除卡券
function activityTypeDelete(activityTypeNo){
  $infoBox.confirmDanger('确认删除？', '请确认是否删除当前奖品？', () => {
    $activityTypeDelete(activityTypeNo).then(res => {
      $infoBox.message.success('删除成功！')
      infoTableRef.value.refTable(true)
    })
  })
}
/* 查询时间更改 */
function queryTimeChange(dates:  [string, string], dateStrings: [string, string]){
  if(dates){
    searchData.value['sTime']=dateStrings[0]
    searchData.value['eTime']=dateStrings[1]
  }else{
    delete searchData.value['sTime']
    delete searchData.value['eTime']
  }
}

</script>
